package com.zhp.farmerclient.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhp.farmerclient.entity.Post;
import lombok.Data;
import lombok.ToString;
import org.apache.poi.ss.formula.functions.T;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Data
@ToString
public class Result implements Serializable {
 private Integer code;
 private String msg;
 private Object object;
 private Map<String,Object> data = new HashMap<>();

 public static Result succ() {
 return succ(200,"操作成功");
 }

 public static Result succ(Object object){
     return succ(200,"操作成功",object);
 }

    private static Result succ(int code, String msg, Object object) {
        Result m = new Result();
        m.setCode(code);
        m.setMsg(msg);
        m.setObject(object);
        return m;
    }

    public static Result succ(int code, String msg) {
        Result m = new Result();
        m.setCode(code);
        m.setMsg(msg);
        return m;
    }

 public static Result fail(String msg) {
 return fail(400,msg);
 }

    public static Result fail(int code, String msg) {
        Result m = new Result();
        m.setCode(code);
        m.setMsg(msg);
        return m;
    }


    public Result data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public static Result succ(Object data,Long total){
        Result m = new Result();
        m.setCode(200);
        m.setMsg("操作成功");
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("list", data);
        resultMap.put("total", total);
        m.setData(resultMap);
        return m;
    }

}